home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / SQLiteDbOption.class.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  10.9 KB  |  250 lines

  1. <?php
  2. /**
  3. * Web based SQLite management
  4. * Class for manage database options
  5. * @package SQLiteManager
  6. * @author FrΘdΘric HENNINOT
  7. * @version $Id: SQLiteDbOption.class.php,v 1.31 2006/04/14 15:16:52 freddy78 Exp $ $Revision: 1.31 $
  8. */
  9.  
  10. /**
  11. * Web based SQLite management
  12. * Class for manage database options
  13. * @package SQLiteManager
  14. * @author FrΘdΘric HENNINOT
  15. * @version $Id: SQLiteDbOption.class.php,v 1.31 2006/04/14 15:16:52 freddy78 Exp $ $Revision: 1.31 $
  16. */
  17. class SQLiteDbOption {
  18.     
  19.     /**
  20.     * reference to the connection object
  21.     *
  22.     * @access public
  23.     * @var object
  24.     */
  25.     var $connId;
  26.     
  27.     /**
  28.     * Class constructor
  29.     *
  30.     * @access public
  31.     * @param string $conn reference to the connection object
  32.     */
  33.     function SQLiteDbOption(&$connId){
  34.         $this->connId = $connId;
  35.         switch($GLOBALS['option_action']){
  36.             case '':
  37.                 $this->optionView();
  38.                 break;
  39.             case 'check':
  40.                 $query = 'PRAGMA integrity_check;';
  41.                 $res = $this->connId->getResId($query);
  42.                 if($res) $tabRes = $this->connId->getArray();
  43.                 $this->_getError($query, $res);
  44.                 echo '<center><br>Result : '.$tabRes[0]['integrity_check'].'<br></center>';
  45.                 $this->optionView();
  46.                 break;
  47.             case 'vacuum':
  48.                 $query = 'VACUUM;';
  49.                 $res = $this->connId->getResId($query);
  50.                 displayQuery($query);
  51.                 $this->optionView();
  52.                 break;
  53.             case 'save':
  54.                 $query[] = 'PRAGMA '.(($this->connId->connId->getVersion()==3)? '' : 'default_' ).'synchronous='.$_POST['synchro'].';';
  55.                 $query[] = 'PRAGMA default_cache_size='.$_POST['cache_size'].';';
  56.                 $query[] = 'PRAGMA '.(($this->connId->connId->getVersion()==3)? '' : 'default_' ).'temp_store='.$_POST['temp_store'].';';
  57.                 foreach($query as $req) $res = $this->connId->getResId($req);
  58.                 $this->optionView();                
  59.                 break;
  60.         }
  61.     }
  62.     
  63.     /**
  64.     * Display Available Option
  65.     *
  66.     * @access public    
  67.     */
  68.     function optionView(){
  69.         if($tabInfoDb = @stat($this->connId->baseName)){
  70.             if($tabInfoDb['size']<1024) {
  71.                 $size = $tabInfoDb['size'].'o';
  72.             } elseif($tabInfoDb['size']< (1024*1024)){
  73.                 $size = number_format(($tabInfoDb['size']/1024), 2, ',', '').'Ko';
  74.             } elseif($tabInfoDb['size']< (1024*1024*1024)){
  75.                 $size = number_format(($tabInfoDb['size']/(1024*1024)), 2, ',', '').'Mo';            
  76.             }
  77.             $perm = substr(sprintf("%o", fileperms($this->connId->baseName)), 3);
  78.             for($i=0 ; $i<3 ; $i++){
  79.                 $currPerm = substr($perm, $i, 1);
  80.                 $strPerm = '';
  81.                 if($currPerm & 4) $strPerm .= 'r'; else $strPerm .= '-';
  82.                 if($currPerm & 2) $strPerm .= 'w'; else $strPerm .= '-';
  83.                 if($currPerm & 1) $strPerm .= 'x'; else $strPerm .= '-';
  84.                 $tabPerm[$i] = $strPerm;
  85.             }
  86.             $perms = $tabPerm[2].$tabPerm[1].$tabPerm[0];
  87.             $dateModif = date('d-m-Y H:i:s', $tabInfoDb['mtime']);
  88.         }
  89.         $res = $this->connId->getResId('PRAGMA '.(($this->connId->connId->getVersion()==3)? '' : 'default_' ).'synchronous;');
  90.         $tabSynchro = $this->connId->getArray();
  91.         if(isset($tabSynchro[0])) $valSynchro = $tabSynchro[0]['synchronous']; else $valSynchro = "";
  92.         $res = $this->connId->getResId('PRAGMA cache_size;');
  93.         $tabCache = $this->connId->getArray();
  94.         if(isset($tabCache[0])) $valCache = $tabCache[0]['cache_size']; else $valCache = "";
  95.         $res = $this->connId->getResId('PRAGMA '.(($this->connId->connId->getVersion()==3)? '' : 'default_' ).'temp_store;');
  96.         $tabTempStore = $this->connId->getArray();
  97.         if(isset($tabTempStore[0])) $valTempStore = $tabTempStore[0]['temp_store']; else $valTempStore = "";
  98.         if(DEMO_MODE) $dbLocation = '/***/***/'.basename($this->connId->baseName);
  99.         else $dbLocation = $this->connId->baseName;
  100.         $ModifPropOk = (!$GLOBALS['workDb']->isReadOnly() && displayCondition('properties'));
  101.         echo '    <center><table width="80%"><tr><td align="center">';
  102.         echo '    <fieldset><legend>'.$GLOBALS['traduct']->get(178).'</legend>';
  103.         echo '
  104.                     <table cellspacing="0" cellpadding="4">
  105.                         <tr><td> </td><td>
  106.                             <table>
  107.                                 <tr bgcolor="#e7dfce"><td class="Browse"><span class="infosTitle">'.$GLOBALS['traduct']->get(179).' </span></td><td class="Browse"><span class="infos">'.$dbLocation.'</span></td></tr>
  108.                                 <tr bgcolor="#f7f3ef"><td class="Browse"><span class="infosTitle">'.$GLOBALS['traduct']->get(180).' </span></td><td class="Browse"><span class="infos">'.$size.'</span></td></tr>
  109.                                 <tr bgcolor="#e7dfce"><td class="Browse"><span class="infosTitle">'.$GLOBALS['traduct']->get(181).' </span></td><td class="Browse"><span class="infos">'.$perms.'</span></td></tr>
  110.                                 <tr bgcolor="#f7f3ef"><td class="Browse"><span class="infosTitle">'.$GLOBALS['traduct']->get(182).' </span></td><td class="Browse"><span class="infos">'.$dateModif.'</span></td></tr>
  111.                             </table>
  112.                         </td></tr>
  113.                     </table>';
  114.         echo "\n\t".'</fieldset>';
  115.         echo "\n\t".'<fieldset><legend>'.$GLOBALS['traduct']->get(212,'Maintenance').'</legend>';
  116.         echo '
  117.                     <table cellspacing="0" cellpadding="4">
  118.                         <tr><td> </td><td>'."\n";
  119.  
  120.         if($ModifPropOk) echo '        <a href="main.php?dbsel='.$GLOBALS['dbsel'].'&action=options&option_action=check" class="base" target="main"> » '.$GLOBALS['traduct']->get(183).'</a><br/><br/>';
  121.         else echo '         » <span class="tabprop"><i>'.$GLOBALS['traduct']->get(183).'</i></span><br/><br/>';
  122.         if($ModifPropOk) echo '        <a href="main.php?dbsel='.$GLOBALS['dbsel'].'&action=options&option_action=vacuum" class="base" target="main"> » '.$GLOBALS['traduct']->get(184).'</a>';
  123.         else echo '         » <span class="tabprop"><i>'.$GLOBALS['traduct']->get(184).'</i></span>';
  124.         echo '
  125.                         </td></tr>
  126.                     </table>';
  127.         echo "\n\t".'</fieldset>';
  128.  
  129.         echo '    <fieldset><legend>'.$GLOBALS['traduct']->get(84).'</legend>';
  130.         echo '  <table align="center" cellpadding="10" cellspacing="5">
  131.                 <tr><td colspan=2 align="center">
  132.                     <form name="formOption" action="main.php?dbsel='.$GLOBALS['dbsel'].'&action=options&option_action=save" method="POST" target="main">
  133.                         <table style="font-size: 11px">
  134.                             <tr>
  135.                                 <td align="right">'.$GLOBALS['traduct']->get(185).' </td>
  136.                                 <td align="right">'.$GLOBALS['traduct']->get(187).'<input type="radio" name="synchro" value="0"'. (($valSynchro==0)? ' checked="checked"' : '' ).(($ModifPropOk)? '' : ' disabled="disabled"'). '></td>
  137.                                 <td align="right">'.$GLOBALS['traduct']->get(188).'<input type="radio" name="synchro" value="1"'. (($valSynchro==1)? ' checked="checked"' : '' ).(($ModifPropOk)? "" : ' disabled="disabled"'). '></td>
  138.                                 <td align="right">'.$GLOBALS['traduct']->get(189).'<input type="radio" name="synchro" value="2"'. (($valSynchro==2)? ' checked="checked"' : '' ).(($ModifPropOk)? '' : ' disabled="disabled"'). '></td>
  139.                             </tr>
  140.                             <tr>
  141.                                 <td align="right">'.$GLOBALS['traduct']->get(186).' </td>
  142.                                 <td colspan="3"><input type="text" class="text" name="cache_size" value="'.$valCache.'" size="5"'.(($ModifPropOk)? '' : ' disabled="disabled"' ).'></td>
  143.                             </tr>
  144.                             <tr>
  145.                                 <td align="right">'.$GLOBALS['traduct']->get(193).' </td>
  146.                                 <td align="right">'.$GLOBALS['traduct']->get(194).'<input type="radio" name="temp_store" value="0"'.(($valTempStore==0)? ' checked="checked"' : '' ).(($ModifPropOk)? '' : " disabled" ).'></td>
  147.                                 <td align="right">'.$GLOBALS['traduct']->get(195).'<input type="radio" name="temp_store" value="1"'.(($valTempStore==1)? ' checked="checked"' : '' ).(($ModifPropOk)? '' : " disabled" ).'></td>
  148.                                 <td align="right">'.$GLOBALS['traduct']->get(196).'<input type="radio" name="temp_store" value="2"'.(($valTempStore==2)? ' checked="checked"' : '' ).(($ModifPropOk)? '' : " disabled" ).'></td>
  149.                             </tr>
  150.                         </table>
  151.                         <br>';
  152.         if($ModifPropOk) echo '            <input class="button" type="submit" value="'.$GLOBALS['traduct']->get(200,'Update').'">';
  153.         echo '        </form>
  154.                 </td></tr>
  155.                 </table>';
  156.         echo '</fieldset></td></tr></table>';
  157.         echo $this->attachDb().'</center>'; 
  158.         
  159.     }
  160.     
  161.     /**
  162.     * Display SQlite error
  163.     *
  164.     * @access public    
  165.     * @param string $queryDisplay Query to display
  166.     * @param resource $res Database connection resource
  167.     */    
  168.     function _getError($queryDisplay, $res){
  169.         if(!$res){
  170.             $errorMessage .= $GLOBALS['traduct']->get(9).' : '.@$this->connId->connId->getError."\n";
  171.         }
  172.         displayQuery($queryDisplay);
  173.         if(!empty($errorMessage)) displayError($errorMessage);
  174.  
  175.     }
  176.     
  177.     /**
  178.     * Database attachment management and display
  179.     *
  180.     * @access public    
  181.     */    
  182.     function attachDb(){
  183.         // save form result Or Del attach database    
  184.         if(isset($_REQUEST['attach_action']) && $_REQUEST['attachId']){
  185.             switch($_REQUEST['attach_action']){
  186.                 case 'add':
  187.                     $query = 'INSERT INTO attachment (base_id, attach_id) VALUES ('.quotes($GLOBALS['dbsel']).', '.quotes($_REQUEST['attachId']).');';
  188.                     break;
  189.                 case 'del':
  190.                     $query = 'DELETE FROM attachment WHERE id='.quotes($_REQUEST['attachId']).';';
  191.                     break;
  192.             }
  193.             $GLOBALS['db']->query($query);
  194.         }
  195.         //echo "<script type=\"text/javascript\">parent.left.location.reload();</script>";
  196.         // display attach database attach and form to add it
  197.         $out = '<table width="80%"><tr><td align="center">';
  198.         $out .= '<fieldset><legend>'.$GLOBALS['traduct']->get(146).'</legend>
  199.                     <table class="Browse" cellspacing="0" width="200">
  200.                         <thead>
  201.                             <tr class="Browse">
  202.                                 <td colspan=2 align="center" class="tapPropTitle">'.$GLOBALS['traduct']->get(131).'</td>
  203.                             </tr>
  204.                         </thead>'."\n";
  205.         
  206.         $tabAttach = SQLiteDbConnect::getAttachDb();
  207.         $tabAttachId = array();
  208.         foreach($tabAttach as $attach_id=>$attachInfo){
  209.             $tabAttachId[] = $attach_id;
  210.             $color = ($attach_id%2)? '#f7f3ef':'#e7dfce';
  211.             $out.= '        <tr class="Browse" bgcolor="'.$color.'">
  212.                             <td class="Browse">'.$attachInfo['name'].'</td><td class="Browse" align="center"><a href="?dbsel='.$GLOBALS['dbsel'].'&action=options&options_action=attach&attach_action=del&attachId='.$attachInfo['id'].'">'.displayPics("supprime.gif", $GLOBALS['traduct']->get(86)).'</a></td>
  213.                         </tr>'."\n";
  214.         }        
  215.         $query = 'SELECT * FROM database';
  216.         $tabDb = $GLOBALS['db']->array_query($query, SQLITE_ASSOC);
  217.         $out.= '            <tr class="Browse">
  218.                             <form name="attachDb" method="POST">
  219.                             <td style="padding:5px" colspan="2" align="center">
  220.                                 <select name="attachId">
  221.                                 <option value="">'.$GLOBALS['traduct']->get(227).'</option>'."\n";
  222.         foreach($tabDb as $dbInfo){
  223.             if(!in_array($dbInfo['id'], $tabAttachId) && ($dbInfo['id']!=$GLOBALS['dbsel'])) {
  224.                 $tempDb = $GLOBALS["SQLiteFactory"]->sqliteGetInstance($dbInfo["location"]);    
  225.                 if(is_object($tempDb)) {
  226.                     $versionNum = $tempDb->getVersion();                
  227.                     if($versionNum == $this->connId->connId->getVersion()) {
  228.                         $out.= '<option value="'.$dbInfo['id'].'">'.$dbInfo['name'].'</option>';
  229.                     }
  230.                 }
  231.             }
  232.         }        
  233.         $out.= '                        </select>
  234.                                     <input class="button" type="submit" value="'.$GLOBALS['traduct']->get(43).'">
  235.                             </td>
  236.                             <input type="hidden" name="dbsel" value="'.$GLOBALS['dbsel'].'">
  237.                             <input type="hidden" name="action" value="options">
  238.                             <input type="hidden" name="options_action" value="attach">
  239.                             <input type="hidden" name="attach_action" value="add">
  240.                             </form>
  241.                         </tr>';
  242.         $out .= '            </table>
  243.                 </fieldset>
  244.             </td></tr></table>';
  245.         return $out;
  246.     }
  247.     
  248. }
  249. ?>
  250.